package com.beiming.libra.controller;

import com.beiming.libra.common.enums.ErrorCode;
import com.beiming.libra.domain.ArbitrationCaseArgument;
import com.beiming.libra.domain.dto.requestdto.CaseArgumentRequestDTO;
import com.beiming.libra.helper.Result;
import com.beiming.libra.service.ArbitrationCaseArgumentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @title 答辩书接口
 * @author zhengyu
 * @create_time 2018/6/1
 */
@RestController
@Api(value = "答辩书接口", tags = "答辩书接口")
@RequestMapping("/api/arbitrationCaseArgument")
public class ArbitrationCaseArgumentController {

  @Resource
  private ArbitrationCaseArgumentService arbitrationCaseArgumentService;

  @GetMapping("/{caseId}")
    @ApiOperation(value = "获取答辩书信息", notes = "获取答辩书信息")
    public Result<List<ArbitrationCaseArgument>> listArbitrationCaseArguments(@ApiParam(value = "仲裁申请表id" , required = true) @PathVariable("caseId") String caseId) {
    if (StringUtils.isEmpty(caseId)) {
      return Result.failed(ErrorCode.ILLEGAL_PARAMETER, "caseId参数必传");
    }
    List<ArbitrationCaseArgument> arbitrationCaseArgumentList = arbitrationCaseArgumentService.listArbitrationCaseArguments(caseId);
    return Result.success(arbitrationCaseArgumentList);
  }

  @ApiOperation("保存答辩书信息")
  @PostMapping("")
  public Result createArbitrationCaseArguments(@RequestBody CaseArgumentRequestDTO caseArgumentRequestDTO) {
    //新增答辩书
    arbitrationCaseArgumentService.saveArbitrationCaseArgument(caseArgumentRequestDTO);
    return Result.success();
  }

  @ApiOperation("修改答辩书信息")
  @PutMapping("")
  public Result updateArbitrationCaseArguments(@ApiParam(value = "答辩书id" , required = true)  String id,
      @ApiParam(value = "答辩内容" , required = true)  String argumentContent) {
    //修改信息
    ArbitrationCaseArgument argument =  arbitrationCaseArgumentService.getArbitrationCaseArgument(id);
    if (null == argument) {
      return Result.failed(ErrorCode.ILLEGAL_PARAMETER, "答辩书不存在");
    }
    argument.setArgumentContent(argumentContent);
    arbitrationCaseArgumentService.updateArbitrationCaseArgument(argument);
    return Result.success();
  }

}
